<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ page import="com.gouwudai.gobbs.pojo.TbbsClass,com.gouwudai.gobbs.pojo.TbbsTopic" %>
<%@ include file="../common/common.jsp" %>
<%@ include file="user_pass2.jsp" %>
<%
int classId = ParamUtils.getIntParameter(request, "classId", 0);
int topicId =  ParamUtils.getIntParameter(request,"topicId");

String action = ParamUtils.getStringParameter(request, "action");

String actionName = "";
if(action.equals("best")){
	userLogin.hasClassPermission(classId,3004);	//加为精品
	actionName = "加为精品";	
}else if(action.equals("lock")){
	userLogin.hasClassPermission(classId,3005);	//锁定主题
	actionName = "锁定主题";	
}else if(action.equals("nobest")){	
	userLogin.hasClassPermission(classId,3004);	//解除精品
	actionName = "解除精品";	
}else if(action.equals("move")){
	userLogin.hasClassPermission(classId,3002);	//移动主题
	actionName = "移动主题";
}else if(action.equals("top")){
	userLogin.hasClassPermission(classId,3006);	//置顶主题
	actionName = "置顶主题";
}else if(action.equals("manage")){
	userLogin.hasClassPermission(classId,3007);	//主题加(扣)分
	actionName = "主题加(扣)分";
}

IClassService classService = (IClassService)BeanManager.getBean("classService");
TbbsClass currentClass = null;
/***************** 需要验证当前用户对当前版面的权限 *********************/
//判断当前版面是否存在
try
{
	currentClass = classService.load(new Integer(classId));
}
catch(Exception e)
{
	HtmlConst.errors(out,7,"您浏览的版面不存在或已被删除！");
	return;
}
//判断用户类型 START
IClassUserService classUserService = (IClassUserService)BeanManager.getBean("classUserService");
int operatorType = 0;//当前用户的类型，-1：游客，0：普通，1:发帖人，2：版主
if(classUserService.isClassManager(new Integer(classId),USER_ID))	//验证用户是否为版主
{
	operatorType = 2;
}
//判断用户类型 END
if(operatorType<2)
{
	HtmlConst.errors(out,1,"您不是该版的版主，没有当前操作的权限！");
	return;
}
/********************* 权限管理模块 END ******************************/
String className = currentClass.getClassName();
//目前支持3级栏目
Integer parentId = currentClass.getParentId();//父栏目ID，如果不为空则说明有父栏目
String parentName = "";
TbbsClass parentClass = null;
Integer grandId = null;//二级父栏目ID，如果不为空则说明有父栏目
String grandName = "";
TbbsClass grandIdClass = null;
if(parentId!=null&&parentId.intValue()>0)
{
	parentClass = classService.load(parentId);	
	parentName = parentClass.getClassName();
	grandId = parentClass.getParentId();
}
if(grandId!=null&&grandId.intValue()>0)
{
	grandIdClass = classService.load(grandId);	
	grandName = grandIdClass.getClassName();
}

StringBuilder totalClassName = new StringBuilder(50);//栏目全名，包括父栏目
if(grandId!=null&&grandId.intValue()>0)
{
	totalClassName.append(grandIdClass.getClassName());
	totalClassName.append(" - ");
}
if(parentId!=null&&parentId.intValue()>0)
{
	totalClassName.append(parentClass.getClassName());
	totalClassName.append(" - ");
}
totalClassName.append(currentClass.getClassName());
//********************************************************************
//--------------------- 读取主题信息 --------------------------
ITopicService topicService = (ITopicService)BeanManager.getBean("topicService");
TbbsTopic tbbsTopic = null;

//判断当前主题是否存在
try
{
	tbbsTopic = topicService.load(new Integer(topicId));
}	
catch(Exception e)
{
	HtmlConst.errors(out,6,"您浏览的主题不存在或已被删除！");
	return;
}
	
String title = tbbsTopic.getTitle();
%><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><%=SYSTITLE%> - <%=actionName %></title>
<meta name="Keywords" content="<%=SYSMETAKEY%>" />
<meta name="Description" content="<%=SYSMETADESC%>" />
<%@ include file="../common/meta.inc" %>
<link rel="stylesheet" type="text/css" href="css/defaultStyle.css" >
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
</head>
<body>
<%@ include file="../common/waiting.inc" %>
<SCRIPT language="javascript">
setStatus('<%=SYSTITLE%> - <%=actionName %>');

var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);

function doSubmit()
{
 	var action = "<%=action%>"; //操作类型
 	
 	var obj = {};
	obj[Buffalo.BOCLASS] = "java.util.HashMap";
 	
 	obj.action = action; 	
 	obj.userId = <%=tbbsTopic.getUserId()%>;
 	obj.classId = <%=classId%>;
 	obj.topicId = <%=topicId%>;
 	obj.topicName = "<%=tbbsTopic.getTitle()%>";
 	obj.userCredit = parseFloat($F("userCredit"));
 	obj.userMark = parseFloat($F("userMark"));
 	obj.userMoney = parseFloat($F("userMoney"));
 	obj.reason = $F("reason");
 	obj.msgFlag = sl_parseBoolean(getRadioValue("msgFlag"));
 	obj.opUserId = <%=USER_ID%>;
 	obj.opUserLoginId = "<%=LOGIN_ID%>";
 	obj.opIp = "<%=LOGIN_IP%>"; 	
 	
 	if(action=="move")
 	{
 		obj.saveLink = sl_parseBoolean(getRadioValue("saveLink")); 	
 		obj.moveClassId = $F("moveClassId");	//移动前的版面 
 	}
 	else if(action=="top")	
 	{
 		obj.topicOnTop = getRadioValue("topicOnTop");	//置顶类型
	}
	buffalo.remoteCall("topicServiceAjaxService.doTopicManage",[obj], function(reply) {
       		ajaxSubmit(reply.getResult(),"操作成功！","back");
    	});    
}
</SCRIPT>
<script language="javascript" type="text/javascript" src="template/scripts/topBar.js"></script>
<DIV class="line"></DIV>
<DIV class="list_table_0">
<%=HtmlConst.navMenu(HtmlConst.navClassMenu(new Integer(classId),parentId,grandId,className,parentName,grandName ))%>&gt;&gt;<%=title%>
</DIV>
<DIV class="line"></DIV>
<form name="theform" id="theform" method="post">
<table class="bluetable" width="100%" align="center" cellpadding="2" cellspacing="1">
	<tr>
		<th colspan="2">用户:<%=Arguments.getUserInfoLink(tbbsTopic.getUserId(),tbbsTopic.getLoginId()) %>【<%=title %>】</th>
	</tr>
	<tr>
		<td class="title" width="20%">当前操作类型</td>
		<td><b><%=actionName %></b></td>
	</tr>  
	<tr>
		<td class="title" width="20%">信誉操作</td>
		<td><select id="userCredit" name="userCredit">
			<option value="0">请选择</option>
			<%for(int i=-10; i<=10; i++){				
					out.print("<option value=\""+ i +"\">"+ i +"</option>");				
			}%></select></td>
	</tr>   
	<tr>
		<td class="title">积分操作</td>
		<td><select id="userMark" name="userMark">
			<option value="0">请选择</option>
			<%for(int i=-10; i<=10; i++){				
					out.print("<option value=\""+ i +"\">"+ i +"</option>");				
			}%></select></td>
	</tr> 
	<tr>
		<td class="title">金币操作</td>
		<td><select id="userMoney" name="userMoney">
			<option value="0">请选择</option>
			<%for(int i=-10; i<=10; i++){				
					out.print("<option value=\""+ i +"\">"+ i +"</option>");				
			}%></select></td>
	</tr>
<%if("move".equals(action)) {%>	
	<tr>
		<td class="title">当前版面</td>
		<td><%=currentClass.getClassName() %></td>
	</tr> 
	<tr>
		<td class="title">目标版面</td>
		<td><select id="moveClassId" name="moveClassId">
				<%=Arguments.getClassOptions(1,0) %>
			</select></td>
	</tr>
	<tr>
		<td class="title">是否在原版面保留链接</td>
		<td><input name="saveLink" type="radio" value="0" checked="checked" />不保留
			&nbsp;&nbsp;&nbsp;
			<input name="saveLink" type="radio" value="1" />保留</td>
	</tr>
<%} else if("top".equals(action)) {%>		
	<tr>
		<td class="title">置顶</td>
		<td><input name="topicOnTop" type="radio" value="0" checked="checked" />不置顶
			&nbsp;&nbsp;&nbsp;
			<input name="topicOnTop" type="radio" value="1"/>本版置顶
			&nbsp;&nbsp;&nbsp;
			<input name="topicOnTop" type="radio" value="2"/>分类置顶
			&nbsp;&nbsp;&nbsp;
			<input name="topicOnTop" type="radio" value="3"/>总置顶</td>
	</tr>
<%} %>		
	<tr>
		<td class="title">操作理由</td>
		<td><input id="reason" name="reason" type="text" value="" size="50" maxlength="200" /></td>
	</tr>
	<tr>
		<td class="title">是否用短消息通知作者</td>
		<td><input name="msgFlag" type="radio" value="0" checked="checked" />否
			&nbsp;&nbsp;&nbsp;
			<input name="msgFlag" type="radio" value="1" />是</td>
	</tr>
</table>	
<table class="btntable" width="100%" align="center">
	<tr>
		<td><button class="btn btnEx" id="btnConfirm" name="btnConfirm" title="确定" onclick="javascript:doSubmit();">确定</button>
		&nbsp;&nbsp;&nbsp; 
		<button name="btnBack" class="btn btnEx" onClick="javascript:history.back();">取消</button></td>
	</tr>
</table>					
</form>
<%=COPYRIGHTFOOT%>
<%@ include file="../common/foot.inc"%>
</body>
</html>